<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Fam0040f extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->CI =& get_instance();
		$c_model = $this->session->userdata('formodel');
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');
		$this->load->library('PHPexcel');

	}

	public function index(){
	    $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	    $this->load->view($this->session->userdata('formain'));
	    $this->load->view('layouts/footer');
	 }

	 public function add_form(){
		$this->load->view($this->session->userdata('foradd'));
	}

	public function edit_form($id){
		$this->load->view($this->session->userdata('foredit'));
	}

	public function view_form($id){
		$this->load->view($this->session->userdata('forview'));
	}

	public function getSubCat(){
		echo json_encode($this->fam0010f_model->getSubCat($this->input->post('cat_code')));
	}

	public function update()
	{
		$data = [$this->input->post('asset_id'),
				$this->input->post('assetName'),
				$this->input->post('department'),
				$this->input->post('location'),
				$this->input->post('assetDescription'),
				$this->input->post('brandName'),
				$this->input->post('model'),
				$this->input->post('contractVendor'),
				$this->input->post('assetOwner'),
				$this->session->userdata('user_id')];

		$query = $this->fam0010f_model->update_data($data);
		echo json_encode($query);
	}

	public function insert()
	{
		$data = [$this->session->userdata('company_id'),
				$this->input->post('assetCode'),
				$this->input->post('mainCat'),
				$this->input->post('subCat'),
				$this->input->post('assetName'),
				$this->input->post('department'),
				$this->input->post('location'),
				$this->input->post('purchaseDate'),
				$this->input->post('assetDescription'),
				$this->input->post('brandName'),
				$this->input->post('model'),
				$this->input->post('assetSerNum'),
				$this->input->post('assetCurrency'),
				$this->input->post('assetCost'),
				$this->input->post('dep_yrs'),
				$this->input->post('salvageValue'),
				$this->input->post('bookValue'),
				$this->input->post('depValue'),
				$this->input->post('assetStatus'),
				$this->input->post('contractVendor'),
				$this->input->post('assetOwner'),
				$this->input->post('depCycle'),
				$this->session->userdata('user_id')];

		$query = $this->fam0010f_model->insert_data($data);
		echo json_encode($query);
	}

	public function search(){
		echo json_encode($this->fam0010f_model->search($this->input->post('assetCode'),$this->input->post('mainCat'),$this->input->post('subCat'),$this->input->post('assetName'),$this->input->post('department'),$this->input->post('location'),$this->input->post('assetStatus'),$this->input->post('assetDesc'),$this->input->post('depCycle')));
	}
}
